package handler;

import java.text.SimpleDateFormat;
import java.util.Date;

import model.Control;

public class ControlDataHandler {
	
	public void Datahandle(String result) {
		
		String currentTime =  new SimpleDateFormat(  //当前时间信息
				"yyyy-MM-dd HH:mm:ss").format(new Date());
		Control control = new Control();
		double aver = (Integer.parseInt(result.substring(3,5))+Integer.parseInt(result.substring(8,10))+
				Integer.parseInt(result.substring(13,15))+Integer.parseInt(result.substring(18,20))+
						Integer.parseInt(result.substring(23,25)))/5.0;
		
		control.put("dev1",Integer.parseInt(result.substring(3,5)));
		control.put("dev2",Integer.parseInt(result.substring(8,10)));
		control.put("dev3",Integer.parseInt(result.substring(13,15)));
		control.put("dev4",Integer.parseInt(result.substring(18,20)));
		control.put("dev5",Integer.parseInt(result.substring(23,25)));
		control.put("aver",aver);
		control.put("power",Double.parseDouble(result.substring(33,40))/1000);
		control.put("status",Integer.parseInt(result.substring(31,32)));
		control.put("alarm",Integer.parseInt(result.substring(32,33)));
		control.put("start",Integer.parseInt(result.substring(43,45)));
		control.put("end",Integer.parseInt(result.substring(45,47)));
		control.put("set",Integer.parseInt(result.substring(47,49)));
		control.put("speed",Integer.parseInt(result.substring(49,50)));
		control.put("mode",Integer.parseInt(result.substring(50,51)));
		control.put("time",currentTime);
		
		control.save();
		System.out.println("写入数据库成功！！！");
	}
}
